import React, { Component } from 'react';
import { connect } from 'react-redux'  
import { Modal, Form, Input,Select ,Table,Button,Row,Col,} from 'antd';

const FormItem = Form.Item;
const Option = Select.Option;

class ViewSheetModal extends Component {
  constructor(props) {
    super(props);
  }

  
  render() {
    const { children, dispatch,listSheet,currentSize,current,total,inventoryId } = this.props;
    const { getFieldDecorator } = this.props.form;
    const formItemLayout = {
      labelCol: { span: 10 },
      wrapperCol: { span: 12 },
    }; 

    const onViewItem = (id) => {
      dispatch({
        type: 'inventory/onViewItem',
        payload:id,
      })
    }

    const pagination = {
        current:current,
        pageSize:currentSize,
        total: total,
        showSizeChanger: true,
        showTotal: (total => '共' + total + '条'),
        onShowSizeChange(current, size) {
            dispatch({
                type: 'inventory/searchSheetList',
                payload: {...{'pageNum':current, 'pageSize':size,'inventoryId':inventoryId} },
            });
        },
        onChange(current) {
            dispatch({ 
                type: 'inventory/searchSheetList', 
                payload: { ...{'pageNum':current, 'pageSize':currentSize,'inventoryId':inventoryId} },
            });
        },
    };


    const columns = [{
        title: '盘点单状态',
        dataIndex: 'status',
        key: 'status',
        width: 100,
        render: (value, row, index) => {
            return (
              value==1?"未完成":value==2?"已完成":""
            )
        }
      },{
        title: '盘点单名称',
        dataIndex: 'inventorySheetName',
        key: 'inventorySheetName',
        width: 150
      },{
        title: '执行时间',
        dataIndex: 'executeTime',
        key: 'executeTime',
        width: 150,
      },{
        title: '创建时间',
        dataIndex: 'createTime',
        key: 'createTime',
        width: 150
      },{
        title: '操作',
        key: 'operation',
        width: 80,
        render: (text, record) => (
            <span>   
              <a onClick={onViewItem.bind(null, record.id_)}>盘点结果</a> 
            </span>
        ),
    }
    ];  
    return ( 
      <span>
        <Modal           
                maskClosable= {this.props.maskClosable}
                confirmLoading= {this.props.confirmLoading}
                title={this.props.title}
                style={{ top: 50}}
                width={800}
                visible={this.props.visible}
                footer={[
                  <Button  key="close" type="primary" size="large" onClick={this.props.onCancel}>关闭</Button>
                ]}
                onCancel={this.props.onCancel}
                key={this.props.newKey}
        >
         <div style={{width:'auto',height:document.body.clientHeight - 230,position:'relative',backgroundColor:'#fff'}}>
            <div style={{minHeight:'100%'}}>           
             <div style={{minHeight:'100%'}}>
                <div style={{width:'100%',height:'100%'}}>
                      <Table columns={columns}
                          loading={this.props.confirmLoading}
                          rowKey={record => record.id_}                  
                          dataSource={listSheet} 
                          pagination={pagination} 
                          scroll={{ y: document.body.clientHeight - 300}}
                    />
                </div>
            </div>              
            </div>          
        </div>
        </Modal>
        
      </span>
    );
  }
    
}

export default Form.create()(ViewSheetModal)
